package ${packagePath}${servicePackage};

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spa.common.api.vo.Result;
import ${entityPackage}.${entity};
import ${mapperPackage}.${entity}Mapper;

/**
 * ${introduce}
 * author: ${author}
 * date: ${date}
 */
@Service
public class ${entity}Service extends ServiceImpl<${entity}Mapper, ${entity}> {

    @Autowired
	private ${entity}Mapper ${entity?uncap_first}Mapper;
	
	/**
	 * 分页列表查询
	 *
	 * @param ${entity?uncap_first}
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	public Result<Object> queryPageList(HttpServletRequest req, Integer pageNo, Integer pageSize){
		Page<${entity}> page= new Page<>(pageNo, pageSize);
	    LambdaQueryWrapper<${entity}> queryWrapper = new LambdaQueryWrapper<>();
	    Page<${entity}> articlePage = ${entity?uncap_first}Mapper.selectPage(page, queryWrapper);
	    List<${entity}> records = articlePage.getRecords();
	    return Result.resultOK(records);
	}
	
	/**
	 * 添加
	 *
	 * @param testTabel
	 * @return
	 */
	@Transactional
	public Result<Object> insert(${entity} ${entity?uncap_first}) {
	    ${entity?uncap_first}Mapper.insert(${entity?uncap_first});
	    return Result.resultOK("添加成功！");
	}
	
	/**
	 * 编辑
	 *
	 * @param ${entity?uncap_first}
	 * @return
	 */
	@Transactional
	public Result<Object> saveById(${entity} ${entity?uncap_first}) {
	    ${entity?uncap_first}Mapper.updateById(${entity?uncap_first});
	    return Result.resultOK("编辑成功!");
	}
	
	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@Transactional
	public Result<Object> deleteById(int id) {
	    ${entity?uncap_first}Mapper.deleteById(id);
	    return Result.resultOK("删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	public Result<Object> selectById(int id) {
	    ${entity} ${entity?uncap_first} = ${entity?uncap_first}Mapper.selectById(id);
	    return Result.resultOK(${entity?uncap_first});
	}
}